package ModelLayer;
import java.util.ArrayList;

public class MachinesList
{
    
    private ArrayList<Machines> machines;
    private static MachinesList instance;

    public MachinesList()
    {
      machines = new ArrayList<Machines>();
    }
    
    public static MachinesList getInstance()
    {
        if(instance == null)
        {
            instance = new MachinesList();
        }
        return instance;
    }

   
    public void addMachine( Machines newMachine)
    {
       machines.add(newMachine);
    }
    
     public void deleteMachine(long machineId)
    {
        Machines machine = findMachine(machineId);
        machines.remove(machine);
    }

    public Machines findMachine(long machineId)
    {
        boolean machineFound = false;
        int index = 0;
        while(index < machines.size() && !machineFound)
        {
            Machines s = machines.get(index);
            if(s.getMachineId() == machineId)
            {
                machineFound = true; 
            }
            else
            {
                index++;
            }
            
        }
        
        if(machineFound)
        {
            return machines.get(index);
        }
        else
        {
            
            return null;
        }
       }
   }
